var rurl = "/index.php?c=usersAjax&a=reg";
var lurl = "/index.php?c=usersAjax&a=login";
var countdown=120;
$(function() {
    $("#submit").click(function(event) {
        $.post(rurl, {
            un: $("#user_name").val(),
            u: $("#user_email").val(),
            phone: $("#phone").val(),
            p: $("#password").val(),
            v:$('#regvalidate').val(),
            ec:$('#reec').val()
        },
        function(data) {
            if (data.code/1 ==1) {
                location.href = "/index.php?c=main&a=mloginPage";
            } else {
                alert(data.desc);
            }
        },
        "json")
    })
}) 
$(function() {
    $("#button").click(function(event) {
        $.post(lurl, {
            u: $("#login_user_name").val(),
            p: $("#login_password").val(),
            v:$('#login_validate').val()
        },
        function(data) {
            if (data.code/1 == 1) {
                location.href = "/index.php?c=main&a=mIndex";
            } else {
                alert("登陆失败");
            }
        },
        "json")
    })
})
$(function(){
    $('#sendCode').click(function(){
            
            $.ajax({
                        type: "GET",
                        url: "/index.php?c=usersAjax&a=sendValCode&u="+$("#user_email").val(),
                        success: function(result) {
                            result = JSON.parse(result);
                            if(result.code/1 == 1){
                                $(this).next('.hint').html('激活码已经发送到您邮箱，请注意查看！！');
                                return false;
                            }else{ 
                                $(this).next('.hint').html('激活码发送失败，请输入正确邮件地址！！');
                                return false;
                            }
                        }
                    });
                    
                settime();
        });
        function settime(){
            if (countdown == 0) {
                $('#sendCode').attr('disabled',false);
                $('#sendCode').text('发送验证码');
                countdown = 120;
            } else {
                $('#sendCode').attr('disabled',true);
                $('#sendCode').text("重新发送(" + countdown + ")"); 
                countdown--;
                setTimeout(function() {
                    settime()
                },1000)
            }
        }
})